import * as THREE from 'three';

export default class Render extends THREE.EventDispatcher {
  id;
  renderId = '';
  actions = [];
  name = '';
  enabled = true;
  actionMap = {};

  renderTimer = 0;

  constructor(name) {
    super();

    if(name) this.name = name;
    this.id = THREE.MathUtils.generateUUID();
  }

  isEnable() {
    return this.enabled;
  }

  _render() {
    // this.dispatchEvent({ type: Event.RENDER_BEFORE });
    console.log('Render', "是啥")
    this.renderFrame();
    this.renderTimer = 0;
    // this.dispatchEvent({ type: Event.RENDER_AFTER });
  }

  renderFrame() {
    throw new Error('must implement method renderFrame;');
  }

  render() {
    // if (!this.isEnable()) return;
    if (this.renderTimer) return;
    this.renderTimer = requestAnimationFrame(this._render.bind(this));
  }
}